package com.xiaoxi.exam.service;

import com.xiaoxi.exam.dao.ExamToeflMapper;
import com.xiaoxi.exam.model.ExamToeflExample;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class ScheduledService {

  @Autowired
  private ExamToeflMapper examToeflMapper;

  @Scheduled(cron = "0 1 0 * * ?")
  public void scheduled() {
    String date = LocalDate.now().plusDays(3).format(DateTimeFormatter.ofPattern("yyyy年M月d日"));
    ExamToeflExample examToeflExample = new ExamToeflExample();
    examToeflExample.or().andExamMonthLike(date + "%");
    examToeflMapper.deleteByExample(examToeflExample);
  }

}
